package com.ymatou.iapi.sellercs.testcase;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.sellercs.parameter.DeleteDiscourseBean;
import com.ymatou.iapi.sellercs.service.DeleteDiscourseCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.SellerCSIMCallService;
import com.ymttest.database.sqlwapper.YmtSellerCSIMWapper;
import com.ymttest.utils.EnvSetup;
/**
*删除话术分类
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_DeleteDiscourse{
	private static DeleteDiscourseBean deletediscourseBean;
	private static DeleteDiscourseCall deletediscourseCall;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
	private static int zsellerId = Integer.parseInt(EnvSetup.getData("autotest_seller_z"));
	private static YmtSellerCSIMWapper YmtSellerCSIMWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("删除话术");
	}

	@Before
	public void caseUp() {
		deletediscourseBean=new DeleteDiscourseBean();
		deletediscourseCall=new DeleteDiscourseCall();
		YmtSellerCSIMWapper=new YmtSellerCSIMWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(deletediscourseCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_DeleteDiscourse_001() {
		Logger.start(true,"删除分类成功");
		try {
			String title="话术分类";
			String discourse="test";
			String CategoryId=SellerCSIMCallService.getCategoryId(sellerId, title);
			String id=SellerCSIMCallService.AddDiscourse(sellerId, title, discourse);
			deletediscourseBean.setCSId(sellerId);
			deletediscourseBean.setId(id);
			deletediscourseCall.setData(deletediscourseBean);
			deletediscourseCall.callService();			
			Logger.verifyIsContains("200", deletediscourseCall.getString("Status"), "验证Status");	
			Logger.verifyEquals(true, deletediscourseCall.getJsonObject().get("Result").getAsJsonObject().get("Success").getAsBoolean(), "验证Success");	
			List<Map>lm=YmtSellerCSIMWapper.selectIndividualdiscourseByCsid(sellerId);
			Logger.debug(id+":"+lm);
			lm = lm.stream().filter(m -> {
				if (m.get("id") != null) {
					return m.get("id").equals(id);
				} else {
					return false;
				}
			}).collect(Collectors.toList());
			Logger.verifyEquals(0, lm.size(), "查询到对应记录");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_DeleteDiscourse_002() {
		Logger.start(true,"不输入csid失败");
		try {
			String title="话术分类";
			String discourse="test";
			String CategoryId=SellerCSIMCallService.getCategoryId(sellerId, title);
			String id=SellerCSIMCallService.AddDiscourse(sellerId, title, discourse);
//			deletediscourseBean.setCSId(sellerId);
			deletediscourseBean.setId(id);
			deletediscourseCall.setData(deletediscourseBean);
			deletediscourseCall.callService();			
			Logger.verifyIsContains("400", deletediscourseCall.getString("Status"), "验证Status");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_DeleteDiscourse_003() {
		Logger.start(true,"不输入id失败");
		try {
			deletediscourseBean.setCSId(sellerId);
//			deletediscourseBean.setId(id);
			deletediscourseCall.setData(deletediscourseBean);
			deletediscourseCall.callService();			
			Logger.verifyIsContains("400", deletediscourseCall.getString("Status"), "验证Status");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}